package com.yc.baihe.times;

import java.util.Timer;
import java.util.TimerTask;

import javax.servlet.http.HttpSession;

import com.yc.baihe.utils.SessionAttributeNames;

public class MyTimer {
	private TimerTask task=null;
	private Timer timer=new Timer();
	
	public void getTimer(final HttpSession session){
		task=new TimerTask(){
			@Override
			public void run() {
				session.setAttribute(SessionAttributeNames.CHECKCODE, "");
				session.removeAttribute(SessionAttributeNames.CHECKCODE);
				System.out.println("session清空完成...");
			}
		};
		timer.schedule(task, 2*60*1000);//2分钟后执行一次
	}
	public void closeTimer(){
		if(timer!=null){
			timer.cancel();
		}
		if(task!=null){
			task.cancel();
		}
	}
}
